<div class="cartProfile">
  <div class="cartProfiletitle"><%= t "site.cart.title" %></div>
  <% if @order_shops.size > 0 %>
    <% submit_str_path = @for_operator ? order_path(:id => @order.id) : cart_update_path %>
    <%= form_tag(submit_str_path, :method => :put) do |f| %>
      <% total_sum = 0 %>
      <% @order_shops.each do |shop| %>
        <% shop_sum = 0 %>
        <div class="cartShop">
          <% if @for_operator %>
            <div class="cartShopInfoContainer">
              <div class="cartShopProfile">
                <%= render :partial => "shared/profile_field", :locals => {:entity_name => "shop", :entity_field_name => "description", :entity_field_value => shop.description} %>
                <%= render :partial => "shared/profile_field", :locals => {:entity_name => "shop", :entity_field_name => "workhours", :entity_field_value => shop.workhours} %>
                <%= render :partial => "shared/profile_field", :locals => {:entity_name => "shop", :entity_field_name => "kitchenhours", :entity_field_value => shop.kitchenhours} %>
                <%= render :partial => "shared/profile_field", :locals => {:entity_name => "shop", :entity_field_name => "kitchen", :entity_field_value => shop.kitchen} %>
                <%= render :partial => "shared/profile_field", :locals => {:entity_name => "shop", :entity_field_name => "phone", :entity_field_value => shop.phone} %>
                <%= render :partial => "shared/profile_field", :locals => {:entity_name => "shop", :entity_field_name => "mobile", :entity_field_value => shop.mobile} %>
                <%= render :partial => "shared/profile_field", :locals => {:entity_name => "shop", :entity_field_name => "address", :entity_field_value => shop.address} %>
                <%= render :partial => "shared/profile_field", :locals => {:entity_name => "shop", :entity_field_name => "time", :entity_field_value => get_select_value(shop, "shop", "time")} %>
                <%= render :partial => "shared/profile_field", :locals => {:entity_name => "shop", :entity_field_name => "town", :entity_field_value => Town.find(:first, :conditions => ["id = ?", shop.town_id]).name} %>
                <%= render :partial => "shared/profile_field", :locals => {:entity_name => "shop", :entity_field_name => "workhours", :entity_field_value => shop.workhours} %>
              </div>
              <div class="cartShopStaffsContainer">
                <% shop.staffs.each do |staff| %>
                  <div class="cartShopStaffProfile">
                    <div class="cartStaffJobtitle">
                      <%= staff.jobtitle %>
                    </div>
                    <div class="cartStaffName">
                      <span class="cartStaffFirstname"><%= staff.firstname %></span>
                      <span class="cartStaffLastname"><%= staff.lastname %></span>
                    </div>
                    <div class="cartStaffContacts">
                      <%= render :partial => "shared/profile_field", :locals => {:entity_name => "staff", :entity_field_name => "email", :entity_field_value => staff.email} %>
                      <%= render :partial => "shared/profile_field", :locals => {:entity_name => "staff", :entity_field_name => "phone", :entity_field_value => staff.phone} %>
                      <%= render :partial => "shared/profile_field", :locals => {:entity_name => "staff", :entity_field_name => "mobile", :entity_field_value => staff.mobile} %>
                    </div>
                  </div>
                <% end %>
              </div>
            </div>
          <% end %>
          <div class="cartShopHeader">
            <div class="cartShopHeaderName"><%= shop.name %></div>
            <% if @for_operator %>
              <div class="cartShopInfo"></div>
            <% end %>
          </div>
          <div class="cartShopBody">
            <% shop.get_order_categors.each do |categor| %>
              <div class="cartCategor">
                <div class="cartCategorHeader">
                  <span class="cartCategorHeaderName"><%= categor.name %></span>
                </div>
                <div class="cartCategorBody">
                  <div class="cartProduct">
                    <table>
                      <tr>
                        <th class="cartProductLabel cartProductNameLabel"><%= t "site.cart.product.name" %></th>
                        <th class="cartProductLabel cartProductQuantityLabel"><%= t "site.cart.product.quantity" %></th>
                        <th class="cartProductLabel cartProductPriceLabel"><%= t "site.cart.product.price" %></th>
                        <th class="cartProductLabel cartProductSumLabel"><%= t "site.cart.product.sum" %></th>
                        <% if @for_edit %>
                          <th class="cartProductLabel cartProductDeleteLabel"><%= t "site.cart.product.delete" %></th>
                        <% end %>
                      </tr>
                      <% categor.get_order_products.each do |product| %>
                        <tr>
                          <td class="cartProductValue cartProductNameValue"><%= product.name %></td>
                          <td class="cartProductValue cartProductQuantityValue">
                            <% if @for_edit %>
                              <%= quantity(:quantity_increase => "productQuantityIncrease", :quantity_decrease => "productQuantityDecrease") do %>
                                <input class="productQuantity" name="items[<%= product.id %>]" type="text" size="1" value="<%= @items[product.id] %>"/>
                              <% end %>
                            <% else %>
                              <%= @items[product.id] %>
                            <% end %>
                          </td>
                          <td class="cartProductValue cartProductPriceValue"><%= product.price %></td>
                          <td class="cartProductValue cartProductSumValue">
                            <% product_sum = product.price * @items[product.id] %>
                            <%= product_sum %>
                            <% shop_sum += product_sum %>
                          </td>
                          <% if @for_edit %>
                            <td class="cartProductValue cartProductValueDelete">
                              <%= link_to "", cart_item_path(product.id), :method => :delete %>
                            </td>
                          <% end %>
                        </tr>
                      <% end %>
                    </table>
                  </div>
                </div>
              </div>
            <% end %>
          </div>
          <div class="cartShopFooter">
            <% if @for_edit %>
              <div class="cartShopContinue">
                <%= link_to t("site.cart.profile.continue"), categors_path(:time => @time, :town => @town, :shop_id => shop.id) %>
              </div>
            <% end %>
            <div class="cartShopDelSumBlock">
              <div class="cartShopDelivery">
                <span class="cartShopDeliveryLabel"><%= t "site.cart.shop.delivery" %></span>
                <span class="cartShopDeliveryValue"><%= shop.delivery %><% shop_sum += shop.delivery %></span>
                <span class="cartShopDeliverySuffix"><%= t "site.cart.price.suffix" %></span>
              </div>
              <div class="cartShopSum">
                <span class="cartShopSumLabel"><%= t "site.cart.shop.sum" %></span>
                <span class="cartShopSumValue"><%= shop_sum %></span>
                <span class="cartShopSumSuffix"><%= t "site.cart.price.suffix" %></span>
              </div>
            </div>
          </div>
        </div>
        <% total_sum += shop_sum %>
      <% end %>
      <% if @for_operator && @for_edit %>
        <div class="orderFormFields">
          <%= render :partial => "shared/simple_field", :locals => {:field => "address",:type => "text", :entity => :order} %>
          <%= render :partial => "shared/simple_field", :locals => {:field => "phone",:type => "text", :entity => :order} %>
          <%= render :partial => "shared/simple_field", :locals => {:field => "extra_price",:type => "text", :entity => :order} %>
          <%= render :partial => "shared/simple_field", :locals => {:field => "extra_comment",:type => "text", :entity => :order} %>
        </div>
      <% elsif (@for_operator && !@for_edit) || (!@for_operator && !@for_edit) %>
  <div class="orderShowFields">
    <div class="orderShowAdress">
      <span class="orderShowAddressLabel"><%= t "site.cart.profile.address" %></span>
      <span class="orderShowAddressValue"><%= @order.address %></span>
    </div>
    <div class="orderShowPhone">
      <span class="orderShowPhoneLabel"><%= t "site.cart.profile.phone" %></span>
      <span class="orderShowPhoneValue"><%= @order.phone %></span>
    </div>
    <div class="orderShowExtra">
      <span class="orderShowExtraComment"><%= @order.extra_comment %></span>
      <span class="orderShowExtraPrice"><%= @order.extra_price %></span>
    </div>
  </div>
      <% end %>
      <div class="cartProfileTotal">
        <span class="cartProfileTotalLabel"><%= t "site.cart.profile.total" %></span>
        <% total_sum += @order.extra_price if !(!@for_operator && @for_edit) && @order.extra_price   %>
        <span class="cartProfileTotalValue"><%= total_sum %></span>
        <span class="cartProfileTotalSuffix"><%= t "site.cart.price.suffix" %></span>
      </div>
      <div class="cartProfileButtons">
        <% if @for_edit %>
        <div class="cartProfileButton cartProfileButtonUpdate" onclick="$('form').submit();return false;"><%= t "site.cart.profile.update" %></div>
        <% elsif !@for_operator %>
        <%= link_to(t("site.cart.profile.back"), orders_path, :class => "cartProfileButton cartProfileButtonBack") %>
        <% end %>
        <% if @for_operator && @for_edit %>
          <%= link_to(t("orders.submit"), order_submit_path(:id => @order.id), :method => :post, :class => "cartProfileButton cartProfileButtonNext") %>
        <% elsif !@for_operator && @for_edit %>
          <%= link_to(t("site.cart.profile.next"), new_order_path, :class => "cartProfileButton cartProfileButtonNext") %>
        <% elsif !@for_operator && !@for_edit %>
          <%= link_to(t("site.cart.profile.pay"), order_pay_path(:id => @order.id), :method => :post, :class => "cartProfileButton cartProfileButtonPay") %>
        <% end %>
      </div>
    <% end %>
  <% else %>
    <div class="cartEmpty"><%= t "site.cart.empty" %></div>
  <% end %>
</div>